import win32gui
import win32process
import psutil

def list_windows_details():
    windows = []
    def enum_windows_proc(hwnd, extra):
        if win32gui.IsWindowVisible(hwnd):
            window_text = win32gui.GetWindowText(hwnd)
            class_name = win32gui.GetClassName(hwnd)
            _, pid = win32process.GetWindowThreadProcessId(hwnd)
            try:
                process = psutil.Process(pid)
                process_name = process.name()
            except:
                process_name = "Unknown"
            if window_text:  # 只显示有标题的窗口
                window_info = f"标题: {window_text} | 类名: {class_name} | 进程: {process_name}"
                windows.append(window_info)
                print(window_info)
    win32gui.EnumWindows(enum_windows_proc, None)
    return windows

if __name__ == "__main__":
    print("正在枚举所有窗口...")
    windows = list_windows_details()